package com.koron.standard.patrolLine.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koron.standard.patrolLine.bean.po.LinePatrolRecord;
import com.koron.standard.patrolLine.mapper.LinePatrolRecordMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 巡视标准数据记录项(PatrolRecord)表服务实现类
 *
 * @author jzp
 * @since 2021-10-19
 */
@Service
public class LinePatrolRecordService extends ServiceImpl<LinePatrolRecordMapper, LinePatrolRecord> {
    public List<LinePatrolRecord> listByPatrolId(String patrolId) {
        LambdaQueryWrapper<LinePatrolRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LinePatrolRecord::getPatrolId, patrolId);
        return list(wrapper);
    }

    public List<LinePatrolRecord> listByPatrolIds(List<String> patrolIds) {
        LambdaQueryWrapper<LinePatrolRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(LinePatrolRecord::getPatrolId, patrolIds);
        return list(wrapper);
    }

    public void removeByPatrolId(String patrolId) {
        if (StrUtil.isEmpty(patrolId)) {
            return;
        }
        LambdaQueryWrapper<LinePatrolRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LinePatrolRecord::getPatrolId, patrolId);
        wrapper.orderByAsc(LinePatrolRecord::getSort);
        List<LinePatrolRecord> list = list(wrapper);
        removeByIds(list.stream().map(LinePatrolRecord::getId).collect(Collectors.toList()));
    }

}
